package com.goblin.model.order.po;

import com.goblin.model.base.BaseEntity;
import lombok.Data;

import javax.persistence.*;
import java.util.List;

@Data
@Table(name = "t_goods_sku")
@Entity
public class SPU extends BaseEntity {

    @Column(name = "goods_name", columnDefinition = "varchar(255) COMMENT '商品名称'")
    private String goodsName;

    @Column(name = "low_price", columnDefinition = "double(8,2) COMMENT '最低价格'")
    private Double lowPrice;

    @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinTable(name = "t_goods_combine_spu_spec", joinColumns = @JoinColumn(name = "spu_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "specification_id", referencedColumnName = "id"), foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT))
    private List<Spec> specs;

    @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinColumn(name = "brand_id", referencedColumnName = "id", nullable = false, columnDefinition = " int(11) COMMENT '品牌id'")
    private Brand brand;

    @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinTable(name = "t_goods_combine_spu_sku", joinColumns = @JoinColumn(name = "spu_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "sku_id", referencedColumnName = "id"), foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT))
    private List<SKU> skus;

    @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinColumn(name = "store_id", referencedColumnName = "id", nullable = false, columnDefinition = " int(11) COMMENT '商铺id'")
    private Store store;
}
